﻿@{
    ViewBag.Title = " 兑礼网控制中心-订单管理";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<style>
    .fitem label { display: inline-block; margin-top: 10px; width: 110px; }

    .fitems label { display: inline-block; margin-top: 5px; margin-bottom: 5px; width: 70px; }

    .fitems { margin-left: 10px; float: left; padding: 10px 0px; }
</style>
<div id="ToolbarPanel" class="searchbox easyui-panel" title="搜索条件" style="width:100%" data-options="iconCls:'icon-search',collapsible:true,closable:false,collapsed:false">
    <div class="fitems">
        <label>商品名称</label>
        <input id="spmc" class="easyui-textbox" data-options="onChange:search">
    </div>
    <div class="fitems">
        <label>收货人</label>
        <input id="shr" class="easyui-textbox" data-options="onChange:search">
    </div>
    <div class="fitems">
        <label>收货电话</label>
        <input id="shdh" class="easyui-numberbox" data-options="onChange:search">
    </div>
    <div class="fitems">
        <label>收货地址</label>
        <input id="shdz" class="easyui-textbox" data-options="onChange:search">
    </div>
    <div class="fitems">
        <label>收货邮编</label>
        <input id="shyb" class="easyui-textbox" data-options="onChange:search">
    </div>
    <div class="fitems">
        <label>状态</label>
        <input id="zt" class="easyui-combobox"
               data-options="valueField:'Key',textField:'Value',onChange:search,url:'@Url.Action("OrderStateType", "Order")'">
    </div>
    <div class="fitems">
        <label>下单时间</label>
        <input id="startTime" type="text" data-options="onChange:search" class="easyui-datebox">-<input id="endTime" data-options="onChange:search" type="text" class="easyui-datebox">
    </div>
    <div class="fitems">
        <label style="width:130px;">会员名称/电话/兑换码</label>
        <input id="hymc" class="easyui-textbox" data-options="onChange:search">
    </div>
    <div class="fitems">
        <label>会员等级</label>
        <input id="hydj" class="easyui-combobox"
               data-options="valueField:'ID',textField:'Memberlevel',onChange:search,url:'@Url.Action("GetAllLevel", "Member")'">
    </div>
</div>

<div id="toolbar">
    <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-edit" plain="true" onclick="Send()">已发货</a>
</div>
<table id="dg" style="width: 100%;" class="easyui-datagrid" method="POST" url="@Url.Action("GetList", "Order")" toolbar="#toolbar" pagination="true" rownumbers="true" fitcolumns="true" singleselect="true" autorowheight="true" resizable="true">
    <thead>
        <tr>
            <th field="WareName">商品名称</th>
            <th field="WarePrice" width="75">商品价格</th>
            <th field="MemberName" width="50" formartter="myfunction">兑换会员</th>
            <th field="Memberlevel" width="50">兑换人等级</th>
            <th field="UserName" width="50">收货人</th>
            <th field="Phone" width="50">收货人电话</th>
            <th field="Address" width="50">收货人地址</th>
            <th field="ZipCode" width="50">收货人邮编</th>
            <th field="StateText" width="50">状态</th>
            <th field="CreateTime" width="50">下单时间</th>
        </tr>
    </thead>
</table>


<script type="text/javascript">
    function myfunction(value, row) {
        return value + '(' + (row.Memberlevel || '无') + ')';
    }


    function search() {
        var spmc = $("#spmc").textbox('getValue');
        var hymc = $("#hymc").textbox('getValue');
        var shr = $("#shr").textbox('getValue');
        var shdh = $("#shdh").textbox('getValue');
        var shdz = $("#shdz").textbox('getValue');
        var shyb = $("#shyb").textbox('getValue');
        var hydj = $("#hydj").combobox('getValue');
        var zt = $("#zt").combobox('getValue');
        var starttime = $('#startTime').datebox('getValue');
        var endtime = $('#endTime').datebox('getValue');
        $('#dg').datagrid('reload', { spmc: spmc, hymc: hymc, shr: shr, shdh: shdh, shdz: shdz, shyb: shyb, hydj: hydj, zt: zt, starttime: starttime, endtime: endtime });
        //$('#dg').datagrid('reload', { spmc: spmc, shr: shr, shdh: shdh, shdz: shdz, shyb: shyb, zt: zt, starttime: starttime, endtime: endtime });
    }


    function Send() {
        $.messager.confirm('警告', '你确定要更改该条数据状态吗?', function (r) {
            if (r) {
                var row = $('#dg').datagrid('getSelected');
                if (row != null && row.State == parseInt('@((int)ExChange.Web.EnumHelper.OrderState.未发货)')) {
                    $.post('@Url.Action("UpdateSendState", "Order")', { id: row.ID }, function (data) {
                        if (data.success == true) {
                            $('#dg').datagrid('reload');    // 重新加载表数据
                        }
                    });
                }
                else {
                    $.messager.alert("警告", "请选择一条！");
                }
            }
        });
    }
</script>
